﻿Imports System
Imports System.Collections.Generic

Namespace System.Workflow.ComponentModel
    Public Class PropertyMetadata
        ' Methods
        Public Sub New()
            Me.options = DependencyPropertyOptions.Default
        End Sub

        Public Sub New(ByVal defaultValue As Object)
            Me.New(defaultValue, 0)
        End Sub

        Public Sub New(ByVal options As DependencyPropertyOptions)
            Me.New(Nothing, options)
        End Sub

        Public Sub New(ByVal ParamArray attributes As Attribute())
            Me.New(Nothing, 0, Nothing, Nothing, attributes)
        End Sub

        Public Sub New(ByVal defaultValue As Object, ByVal ParamArray attributes As Attribute())
            Me.New(defaultValue, 0, Nothing, Nothing, attributes)
        End Sub

        Public Sub New(ByVal defaultValue As Object, ByVal options As DependencyPropertyOptions)
            Me.New(defaultValue, options, Nothing, Nothing, New Attribute(0  - 1) {})
        End Sub

        Public Sub New(ByVal options As DependencyPropertyOptions, ByVal ParamArray attributes As Attribute())
            Me.New(Nothing, options, Nothing, Nothing, attributes)
        End Sub

        Public Sub New(ByVal defaultValue As Object, ByVal options As DependencyPropertyOptions, ByVal ParamArray attributes As Attribute())
            Me.New(defaultValue, options, Nothing, Nothing, attributes)
        End Sub

        Public Sub New(ByVal defaultValue As Object, ByVal options As DependencyPropertyOptions, ByVal getValueOverride As GetValueOverride, ByVal setValueOverride As SetValueOverride)
            Me.New(defaultValue, options, getValueOverride, setValueOverride, New Attribute(0  - 1) {})
        End Sub

        Public Sub New(ByVal defaultValue As Object, ByVal options As DependencyPropertyOptions, ByVal getValueOverride As GetValueOverride, ByVal setValueOverride As SetValueOverride, ByVal ParamArray attributes As Attribute())
            Me.New(defaultValue, options, getValueOverride, setValueOverride, False, attributes)
        End Sub

        Friend Sub New(ByVal defaultValue As Object, ByVal options As DependencyPropertyOptions, ByVal getValueOverride As GetValueOverride, ByVal setValueOverride As SetValueOverride, ByVal shouldAlwaysCallOverride As Boolean, ByVal ParamArray attributes As Attribute())
            Me.options = DependencyPropertyOptions.Default
            Me.defaultValue = defaultValue
            Me.options = options
            Me.getValueOverride = getValueOverride
            Me.setValueOverride = setValueOverride
            Me.shouldAlwaysCallOverride = shouldAlwaysCallOverride
            Me.attributes = attributes
        End Sub

        Public Function GetAttributes() As Attribute()
            Return Me.GetAttributes(Nothing)
        End Function

        Public Function GetAttributes(ByVal attributeType As Type) As Attribute()
            Dim list As New List([Of] Attribute)
            If (Not Me.attributes Is Nothing) Then
                Dim attribute As Attribute
                For Each attribute In Me.attributes
                    If ((Not attribute Is Nothing) AndAlso ((attributeType Is Nothing) OrElse (attribute.GetType Is attributeType))) Then
                        list.Add(attribute)
                    End If
                Next
            End If
            Return list.ToArray
        End Function

        Protected Overridable Sub OnApply(ByVal dependencyProperty As DependencyProperty, ByVal targetType As Type)
        End Sub

        Friend Sub Seal(ByVal dependencyProperty As DependencyProperty, ByVal targetType As Type)
            Me.OnApply(dependencyProperty, targetType)
            Me.propertySealed = True
        End Sub


        ' Properties
        Public Property DefaultValue As Object
            Get
                Return Me.defaultValue
            End Get
            Set(ByVal value As Object)
                If Me.propertySealed Then
                    Throw New InvalidOperationException(SR.GetString("Error_SealedPropertyMetadata"))
                End If
                Me.defaultValue = value
            End Set
        End Property

        Public Property GetValueOverride As GetValueOverride
            Get
                Return Me.getValueOverride
            End Get
            Set(ByVal value As GetValueOverride)
                If Me.propertySealed Then
                    Throw New InvalidOperationException(SR.GetString("Error_SealedPropertyMetadata"))
                End If
                Me.getValueOverride = value
            End Set
        End Property

        Public ReadOnly Property IsMetaProperty As Boolean
            Get
                Return (CByte((Me.options And DependencyPropertyOptions.Metadata)) > 0)
            End Get
        End Property

        Public ReadOnly Property IsNonSerialized As Boolean
            Get
                Return (CByte((Me.options And DependencyPropertyOptions.NonSerialized)) > 0)
            End Get
        End Property

        Public ReadOnly Property IsReadOnly As Boolean
            Get
                Return (CByte((Me.options And DependencyPropertyOptions.ReadOnly)) > 0)
            End Get
        End Property

        Protected ReadOnly Property IsSealed As Boolean
            Get
                Return Me.propertySealed
            End Get
        End Property

        Public Property Options As DependencyPropertyOptions
            Get
                Return Me.options
            End Get
            Set(ByVal value As DependencyPropertyOptions)
                If Me.propertySealed Then
                    Throw New InvalidOperationException(SR.GetString("Error_SealedPropertyMetadata"))
                End If
                Me.options = value
            End Set
        End Property

        Public Property SetValueOverride As SetValueOverride
            Get
                Return Me.setValueOverride
            End Get
            Set(ByVal value As SetValueOverride)
                If Me.propertySealed Then
                    Throw New InvalidOperationException(SR.GetString("Error_SealedPropertyMetadata"))
                End If
                Me.setValueOverride = value
            End Set
        End Property

        Friend ReadOnly Property ShouldAlwaysCallOverride As Boolean
            Get
                Return Me.shouldAlwaysCallOverride
            End Get
        End Property


        ' Fields
        Private attributes As Attribute()
        Private defaultValue As Object
        Private getValueOverride As GetValueOverride
        Private options As DependencyPropertyOptions
        Private propertySealed As Boolean
        Private setValueOverride As SetValueOverride
        Private shouldAlwaysCallOverride As Boolean
    End Class
End Namespace

